package com.gimi.cloud.bbp.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 唯一编码生成工厂
 * @author  XX
 * @date 2017-12-01
 * @version  1.0
 */
public class  SeqFactory{

	private static final int maxRandomNum = 99999;
	private static final int mixRandomNum = 10000;
	/**
	 * 原子操作的Integer ,确保5位数字
	 */
	private static AtomicInteger randomAppeadNum = new AtomicInteger(mixRandomNum);
	private static final SimpleDateFormat DateFormat = new SimpleDateFormat("yyMMddHHmmssSSS");
	private static final SimpleDateFormat DateFormatProd = new SimpleDateFormat("HHmmssSSS");
	
	/**
	 * 当前时间[20160929 + 5位自增数]
	 * @return
	 */
	public synchronized static final String getOrderNO(){
		randomAppeadNum.compareAndSet(maxRandomNum, mixRandomNum);
		int rand = randomAppeadNum.incrementAndGet();
		String _NO = DateFormat.format(new Date()) + rand;
		return _NO;
	}

	/**
	 * 获取产品id
	 * @return
	 */
	public synchronized static final String getProdId(){
		randomAppeadNum.compareAndSet(maxRandomNum, mixRandomNum);
		int rand = randomAppeadNum.incrementAndGet();
		String prodId = DateFormatProd.format(new Date()) + rand;
		return prodId;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
